
/**
 * Module dependencies.
 */






var config = require('./config');
var cluster = require('cluster');


// all environments


var Server = require('./server').Server;

var numCPUs = require('os').cpus().length;



var command = require('optimist')
    .usage('Usage : $0 --port [num]  --mongodburl [url] --redisurl [url] --debug')
    .alias('p', 'port')
    .alias('m', 'mongodburl')
    .alias('r', 'redisurl')
    .alias('d', 'debug');



config.servicePort = command.argv.p || Number(config.servicePort) || 3003;
config.mongoDbUrl = command.argv.m || config.mongoDbUrl;
config.redisUrl = command.argv.r || config.redisUrl;
config.isDebug = command.argv.d || false;

new Server(config.servicePort, config.mongoDbUrl, config.redisUrl).start(function(err)
{
    console.log(config.servicePort);
});


/*if (cluster.isMaster) {
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', function(worker, code, signal) {
    console.log('worker %d died (%s). restarting...', worker.process.pid, signal || code);
    cluster.fork();
  });
} else {*/


  // Workers can share any TCP connection
  // In this case its a HTTP server


//}

